package com.fz.us.oa.core.entity.com;

import com.fz.us.admin.company.entity.BaseFlowEntity;
import com.fz.us.admin.company.entity.Department;
import com.fz.us.admin.company.entity.User;
import com.fz.us.admin.dict.entity.DictItem;
import com.fz.us.oa.core.entity.common.FileManage;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * 业务实体类 - 发文申请表
 * ============================================================================
 * 版权所有 2017 。
 *
 * @author XuHeng
 * @version 1.0 2017-02-08 。
 * ============================================================================
 */
@Entity
@Table(name="ec_outfile")
public class Outfile extends BaseFlowEntity {

    private static final long serialVersionUID = -7239272632853565039L;

    /**
     * 发文类别
     */
    private DictItem dictItem;

    /**
     * 发文标题 name
     */

    /**
     * 文件编号
     */
    private String fileNo;

    /**
     * 发文时间
     */
    private Date datPulished;

    /**
     * 发文对象 0:全体员工（默认全体员工）  1:部门    2:个人
     */
    private int noticeType;

    /**
     * 部门
     */
    private Set<Department> noticeDepartments;

    /**
     * 通知个人
     */
    private Set<User> noticeUsers;

    /**
     * 会签对象
     */
    private Set<User> viewers;
    private String viewerIds;

    /**
     * 相关附件
     */
    private List<FileManage> file;

    /**
     * 提交日期
     */
    private Date dateApply;
    /**
     * 文档状态数值
     */
    private int numStatus;
    /**
     * 文档状态文字
     */
    private String txtStatus;

    /**
     * 修订次数
     */
    private int numRevise;
    /**
     * 调整日期
     */
    private Date dateUpdate;
    /**
     * 文档调整UNID
     */
    private String updateUnid;

    /**
     * 表单名称
     */
    private String form;

    @Column(nullable=false, columnDefinition = "varchar(50) default '发文申请表'")
    public String getForm() {
        return form;
    }

    public void setForm(String form) {
        this.form = form;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public DictItem getDictItem() {
        return dictItem;
    }

    public void setDictItem(DictItem dictItem) {
        this.dictItem = dictItem;
    }

    public int getNoticeType() {
        return noticeType;
    }

    public void setNoticeType(int noticeType) {
        this.noticeType = noticeType;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @OrderBy("pinYinHead asc")
    public Set<Department> getNoticeDepartments() {
        return noticeDepartments;
    }

    public void setNoticeDepartments(Set<Department> noticeDepartments) {
        this.noticeDepartments = noticeDepartments;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name="outfile_noticer",
            joinColumns={@JoinColumn(name="outfile_id")},
            inverseJoinColumns={@JoinColumn(name="user_id")}
    )
    public Set<User> getNoticeUsers() {
        return noticeUsers;
    }

    public void setNoticeUsers(Set<User> noticeUsers) {
        this.noticeUsers = noticeUsers;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "ec_outfile_file", joinColumns = @JoinColumn(name="id"),inverseJoinColumns = @JoinColumn(name="fileId"))
    public List<FileManage> getFile() {
        return file;
    }

    public void setFile(List<FileManage> file) {
        this.file = file;
    }

    public String getFileNo() {
        return fileNo;
    }

    public void setFileNo(String fileNo) {
        this.fileNo = fileNo;
    }

    public Date getDatPulished() {
        return datPulished;
    }

    public void setDatPulished(Date datPulished) {
        this.datPulished = datPulished;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name="outfile_viewer",
            joinColumns={@JoinColumn(name="outfile_id")},
            inverseJoinColumns={@JoinColumn(name="user_id")}
    )
    public Set<User> getViewers() {
        return viewers;
    }

    public void setViewers(Set<User> viewers) {
        this.viewers = viewers;
    }

    public Date getDateApply() {
        return dateApply;
    }

    public void setDateApply(Date dateApply) {
        this.dateApply = dateApply;
    }

    public int getNumStatus() {
        return numStatus;
    }

    public void setNumStatus(int numStatus) {
        this.numStatus = numStatus;
    }

    public String getTxtStatus() {
        return txtStatus;
    }

    public void setTxtStatus(String txtStatus) {
        this.txtStatus = txtStatus;
    }

    public int getNumRevise() {
        return numRevise;
    }

    public void setNumRevise(int numRevise) {
        this.numRevise = numRevise;
    }

    public Date getDateUpdate() {
        return dateUpdate;
    }

    public void setDateUpdate(Date dateUpdate) {
        this.dateUpdate = dateUpdate;
    }

    public String getUpdateUnid() {
        return updateUnid;
    }

    public void setUpdateUnid(String updateUnid) {
        this.updateUnid = updateUnid;
    }

    @Type(type="text")
    public String getViewerIds() {
        return viewerIds;
    }

    public void setViewerIds(String viewerIds) {
        this.viewerIds = viewerIds;
    }


}
